export default {
  addReview(context, playLoad){
    return new Promise((resolve, reject)=>{
      context.commit('addToReviewList', playLoad)
      resolve('已记录到记忆录')
    })
},
  deleteReview(context, playLoad){
    return new Promise((resolve, reject)=>{
      context.commit('deleteFromReviewList', playLoad)
      resolve('已经删除一个记录')
    })
  },
  addCollect(context, playLoad){
    return new Promise((resolve, reject)=>{
      let oldCollect = null
      if(context.state.collectList){
        oldCollect = context.state.collectList.find(item=> item.url === playLoad.url)
        if(oldCollect){
          context.commit('delCollectList', playLoad)
          resolve('已从收藏夹中移除一个')
        }else{
          context.commit('addToCollectList', playLoad)
          resolve('已经添加一个到收藏夹')
        }
      }else{
        context.commit('addToCollectList', playLoad)
        resolve('已经添加一个到收藏夹')
      }
      
    })
  },

  // 用户登录操作
  addLogin(context, playLoad){
    return new Promise((resolve, reject)=>{
      let oldUser = null
      if(context.state.userList){
        oldUser = context.state.userList.find(item=>playLoad.userName == item.userName)
        if(oldUser){
          if( oldUser.password == playLoad.password){
            context.commit('addToLogin', playLoad)
            resolve('欢迎回来~' + playLoad.userName)
          }else{
            resolve('输入有误~请重新输入')
          }
        }else{
          // 注册
          context.commit('registerLogin', playLoad)
          resolve('欢迎加入~' + playLoad.userName)
        }
      }else{
        context.commit('registerLogin', playLoad)
        resolve('欢迎加入~' + playLoad.userName)
      }
    })
  }
}

// addReview(context, playLoad) {
//   return new Promise((resolve, reject) => {
//       context.commit('addToReviewList', playLoad)
//       resolve('已加入回顾夹')
//   })

// }